<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>首页</title>
        <script src="js/jquery-3.3.1.js"></script>
        <script>
            $(function () {
                /*1.获取用户名*/
                $.get("getUserNameServlet", {}, function (info) {
                    $("#bname").text(info.data);
                });

                /*2.查询用户数据*/
                $("#but").click(function () {
                    $.get("getUserInfoServlet", {}, function (info) {
                        if(info.flag){
                            $("#id").val(info.data.id);
                            $("#username").val(info.data.username);
                            $("#password").val(info.data.password);
                            $("#email").val(info.data.email);

                            //性别~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            var sex = info.data.sex;
                            if(sex=="男"){
                                $("#divn").html('<input type="radio" name="sex" checked>男 <input type="radio" name="sex">女')
                            }else{
                                $("#divn").html('<input type="radio" name="sex" >男 <input type="radio" name="sex" checked>女')
                            }

                            //爱好~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            var love = info.data.love;
                            var lovestr ='';
                            love.forEach(function (e) {

                                if(e == "1"){
                                    lovestr += '<input type="checkbox" name="love" value="1" checked>篮球';
                                }else if(e == "2"){
                                    lovestr += '<input type="checkbox" name="love" value="2" checked>乒乓球';
                                }else if(e=="3"){
                                    lovestr += '<input type="checkbox" name="love" value="3" checked>羽毛球<br>';
                                }
                            })
                            $("#loven").html(lovestr);





                        }else{
                            alert(info.errorMsg)
                            location.href="login.html";
                        }


                    });
                });
            })
        </script>
    </head>
    <body>
        <h2>首页</h2>
        <p>欢迎你: <b id="bname">zf</b>  </p>
        <form>
            id:<input type="text" name="id" id="id"><br>
            用户名:<input type="text" name="username" id="username"><br>
            密码:<input type="password" name="password" id="password"><br>
            email:<input type="text" name="email" id="email"><br>
            性别:<div id="divn"></div>
            爱好:<div id="loven"></div>
            <input type="button" value="查询用户信息" id="but">
        </form>

    </body>
</html>
